import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch((err) => err)
}
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalReplace.call(this, location, onResolve, onReject)
  }
  return originalReplace.call(this, location).catch((err) => err)
}

const router = new VueRouter({
  base: '/portal',
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      component: () => import('@/views/home/index.vue')
    },
    {
      path: '/flowView',
      component: () => import('@/views/flowView/index.vue')
    },
    {
      path: '/virtual-select',
      component: () => import('@/views/flowView/virtualSelect.vue')
    },
    {
      path: '/portal',
      name: 'portal',
      component: () => import('@/views/portal/index.vue')
    },
    {
      path: '/screen/emissions',
      name: 'screen_emissions',
      component: () => import('@/views/screen/emissions/index.vue')
    }
  ]
})

export default router
